package ynu.edu.api.client.fallback;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import ynu.edu.api.client.UserClient;
import ynu.edu.common.domain.DeductDTO;
import ynu.edu.common.exception.BizIllegalException;

@Component
@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            @Override
            public void deductMoney(DeductDTO dto) {
                log.error("扣款服务降级", cause);
                throw new BizIllegalException("扣款服务繁忙，请稍后重试");
            }
        };
    }
}